package com.erlang.springmvc.controller;

import com.erlang.springmvc.pojo.Customer;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description：
 */
@Controller
@RequestMapping(value = "pojos-type")
public class PojosTypeController {

    @InitBinder
    public void initBinder(WebDataBinder webDataBinder){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:dd");
        webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

    /**
     * @Description 去操作界面
     */
    @RequestMapping(value = "to-pojos-type")
    public ModelAndView toPojosType(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pojos-type");
        return modelAndView;
    }

    /**
     * @Description 去操作界面
     */
    @RequestMapping(value = "do-pojos-type")
    public ModelAndView doPojosType(Customer customer){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("pojos-type");
        modelAndView.addObject("customer", customer.toString());
        return modelAndView;
    }
}